#include <iostream>
#include <vector>
#include <sstream>
#include <fstream>
#include "sql/sql_api.h"

using namespace std;

extern vector<string> gen_sqlite_dict(const string fcInSqlitePath, const string fcInTableName, const string fcInDictSrcPath, const bool fcbInDeleteTable)
{
	vector<string> tResErrorLine;
	WriteDictDatabase tWrDictDb(fcInSqlitePath);

	//------------------
	ifstream tInfileStream(fcInDictSrcPath);
	if( ! tInfileStream ) {
		cout << "字典文件打开失败：" << fcInDictSrcPath << endl;
	}

	string tLine;
	while(getline(tInfileStream, tLine, '\n'))
	{	
		stringstream tSsLine(tLine);
		vector<string> tPhonemes;
		string tTemp;

		string tKey;
		tSsLine >> tKey;
		while(tSsLine >> tTemp) {
			tPhonemes.push_back(tTemp);
		}

		string tValue = "";
		int i = 0;
		for(i=0; i<tPhonemes.size()-1; i++) {
			tValue += tPhonemes[i] + " ";
		}
		tValue += tPhonemes[i];

		//插入数据
		if( false == tWrDictDb.add_sqlite_dict(fcInTableName, fcbInDeleteTable, tKey, tValue) ) {
			tResErrorLine.push_back(tLine);
		}
	}
	tInfileStream.close();
	return tResErrorLine;
}
